package dailyTopic;

/**
 * @author zhangmin
 * @create 2021-08-10 9:15
 * 等差数列划分:双指针
 */
public class numberOfArithmeticSlices413 {
    public int numberOfArithmeticSlices(int[] nums) {
        int n=nums.length;
        if (n<3)
            return 0;
        int[] diffValue=new int[n];
        diffValue[0]=0;
        for (int i = 1; i < n; i++) {
            diffValue[i]=nums[i]-nums[i-1];
            System.out.println("diffvalue"+i+"="+diffValue[i]);
        }
        int cnts=0;
        for (int i = 0; i < n-1; i++) {
            //记录当前正在统计的差值
            int curdiff=diffValue[i+1];
            //记录当前差值连续出现次数
            int diffcnt=1;
            for (int j = i+2; j < n; j++) {
                if (diffValue[j]==curdiff){
                    diffcnt++;
                    System.out.println(j+":"+diffValue[j]);
                    System.out.println("diffcnt="+diffcnt);
                }else {
                    j=n;
                    diffcnt=0;
                }
                if (diffcnt>=2){
                    cnts++;
                    System.out.println("cnts="+cnts);
                }
            }
        }
        return cnts;
    }

    public static void main(String[] args) {
        int[] nums=new int[]{1,2,3,8,9,10};
        numberOfArithmeticSlices413 object=new numberOfArithmeticSlices413();
        System.out.println(object.numberOfArithmeticSlices(nums));
    }
}
